﻿namespace FallingRocks
{
    using System;
    using System.Collections.Generic;

    public static class Menu
    {
        private static readonly Color selectColor = Color.Yellow;

        private static readonly Color introColor1 = Color.Yellow;
        private static readonly Color introColor2 = Color.Yellow;

        private static readonly Color menuColor1 = Color.Yellow;
        private static readonly Color menuColor2 = Color.Yellow;
        private static readonly Color menuColor3 = Color.Yellow;
        private static readonly Color menuColor4 = Color.Yellow;

        private static readonly Color controlColer1 = Color.Yellow;
        private static readonly Color controlColer2 = Color.Yellow;
        private static readonly Color controlColer3 = Color.Yellow;

        private static int selectX = menuX1 + deltaX;
        private static int selectY = menuY1 + deltaY;

        private static readonly int introX1 = 10;
        private static readonly int introX2 = 25;
        private static readonly int introY1 = 5;
        private static readonly int introY2 = 15;

        private static readonly int menuX1 = 26;
        private static readonly int menuX2 = menuX1 - 9;
        private static readonly int menuX3 = menuX1 - 2;
        private static readonly int menuX4 = menuX1 + 8;
        private static readonly int menuY1 = 3;
        private static readonly int menuY2 = 11;
        private static readonly int menuY3 = 19;
        private static readonly int menuY4 = 26;

        private static readonly int controlX1 = 5;
        private static readonly int controlX2 = 35;
        private static readonly int controlX3 = 49;
        private static readonly int controlY1 = 5;
        private static readonly int controlY2 = 5;
        private static readonly int controlY3 = 5;

        public static int selected = 1;

        private static readonly int deltaX = -6;
        private static readonly int deltaY = 3;

        public static void MoveSelectorUp(IRenderer consoleRenderer)
        {
            if (selected == 1)
            {
                selected = 4;
            }
            else
            {
                selected--;
            }

            Console.Clear();
            Console.BackgroundColor = ConsoleColor.Black;
            consoleRenderer.RenderStatic(Menu.menu1);
            consoleRenderer.RenderStatic(Menu.menu2);
            consoleRenderer.RenderStatic(Menu.menu3);
            consoleRenderer.RenderStatic(Menu.menu4);
            Selected(consoleRenderer);
        }

        public static void MoveSelectorDown(IRenderer consoleRenderer)
        {
            if (selected == 4)
            {
                selected = 1;
            }
            else
            {
                selected++;
            }
            Console.Clear();
            Console.BackgroundColor = ConsoleColor.Black;
            consoleRenderer.RenderStatic(Menu.menu1);
            consoleRenderer.RenderStatic(Menu.menu2);
            consoleRenderer.RenderStatic(Menu.menu3);
            consoleRenderer.RenderStatic(Menu.menu4);
                        
            Selected(consoleRenderer);

            // consoleRenderer.RenderStatic(Menu.select);
            //consoleRenderer.RenderStatic(Menu.menu);
        }

        public static void Selected(IRenderer consoleRenderer)
        {
            switch (selected)
            {
                case 1:
                    consoleRenderer.RenderStatic(Menu.menu1,true);
                    break;
                case 2:
                    consoleRenderer.RenderStatic(Menu.menu2, true);
                    break;
                case 3:
                    consoleRenderer.RenderStatic(Menu.menu3, true);
                    break;
                case 4:
                    consoleRenderer.RenderStatic(Menu.menu4, true);
                    break;
                default:
                    break;
            }
        }

        public static List<IRenderable> intro = new List<IRenderable>()
        {
            new MenuItem(new Position(introX1, introY1),     @"________     ____      __      __      __  ___    __    ______".ToCharArray(),introColor1),
            new MenuItem(new Position(introX1, introY1 + 1), @"////////    //  \\     ||      ||      ||  ||\\   ||   //----|/ ".ToCharArray(), introColor1),
            new MenuItem(new Position(introX1, introY1 + 2), @"//         //    \\    ||      ||      ||  || \\  ||  /|".ToCharArray(), introColor1),
            new MenuItem(new Position(introX1, introY1 + 3), @"////////  //======\\   ||      ||      ||  ||  \\ || (|     _____".ToCharArray(), introColor1),
            new MenuItem(new Position(introX1, introY1 + 4), @"//       //        \\  ||      ||      ||  ||   \\||  \|      |\".ToCharArray(), introColor1),
            new MenuItem(new Position(introX1, introY1 + 5), @"//      //          \\ |\\\\\| |\\\\\| ||  //    \_|   \\=====|/".ToCharArray(), introColor1),

            new MenuItem(new Position(introX2, introY2),     @"_______      ______      _____  __   ___  _______".ToCharArray(),introColor2 ),
            new MenuItem(new Position(introX2, introY2 + 1), @"||    \\    //    \\    //    \ ||   //  /|     \\".ToCharArray(),introColor2 ),
            new MenuItem(new Position(introX2, introY2 + 2), @"||     ||  //      \\  //       ||  //   ||".ToCharArray(),introColor2 ),
            new MenuItem(new Position(introX2, introY2 + 3), @"||======) (||      ||)(||       ||-//\   \\_______".ToCharArray(),introColor2 ),
            new MenuItem(new Position(introX2, introY2 + 4), @"||     \\  \\      //  \\       ||/  \\          |\".ToCharArray(),introColor2 ),
            new MenuItem(new Position(introX2, introY2 + 5), @"//      \|  \\____//    \\____/ ||    \\ \_______|/".ToCharArray(),introColor2 )
        };
    
        public static List<IRenderable> menu1 = new List<IRenderable>()
        {
            new MenuItem(new Position(menuX1, menuY1),     @" _______  __________   ____      _______  __________".ToCharArray(),menuColor1 ),
            new MenuItem(new Position(menuX1, menuY1 + 1), @"/|     \\     ||      //  \\     ||    \\     ||".ToCharArray(),menuColor1 ),
            new MenuItem(new Position(menuX1, menuY1 + 2), @"||            ||     //    \\    ||     ||    ||".ToCharArray(),menuColor1 ),
            new MenuItem(new Position(menuX1, menuY1 + 3), @"\\_______     ||    //======\\   ||======)    ||".ToCharArray(),menuColor1 ),
            new MenuItem(new Position(menuX1, menuY1 + 4), @"        |\    ||   //        \\  ||     \\    ||".ToCharArray(),menuColor1 ),
            new MenuItem(new Position(menuX1, menuY1 + 5), @"\_______|/    ||  //          \\ //      \|   ||              ".ToCharArray(),menuColor1 ),
             };
        public static List<IRenderable> menu2 = new List<IRenderable>()
        {
            new MenuItem(new Position(menuX2, menuY2),      @"   ______   _______  __________ __    ______     ___    __  _______".ToCharArray(),menuColor2 ),
            new MenuItem(new Position(menuX2, menuY2 + 1),  @"  //    \\  ||    \\     ||     ||   //    \\    ||\\   || /|     \\".ToCharArray(),menuColor2 ),
            new MenuItem(new Position(menuX2, menuY2 + 2),  @" //      \\ ||     ||    ||     ||  //      \\   || \\  || ||".ToCharArray(),menuColor2 ),
            new MenuItem(new Position(menuX2, menuY2 + 3),  @"(||      ||)||=====/     ||     || (||      ||)  ||  \\ || \\_______".ToCharArray(),menuColor2 ),
            new MenuItem(new Position(menuX2, menuY2 + 4),  @" \\      // ||           ||     ||  \\      //   ||   \\||         |\".ToCharArray(),menuColor2 ),
            new MenuItem(new Position(menuX2, menuY2 + 5),  @"  \\____//  ||           ||     ||   \\____//    ||    \_| \_______|/".ToCharArray(),menuColor2 ),
             };
        public static List<IRenderable> menu3 = new List<IRenderable>()
        {
            new MenuItem(new Position(menuX3, menuY3),     @"     ____     ______      ______   __     __ __________".ToCharArray(),menuColor3),
            new MenuItem(new Position(menuX3, menuY3 + 1), @"    //  \\    ||    \    //    \\  ||     ||     ||".ToCharArray(),menuColor3),
            new MenuItem(new Position(menuX3, menuY3 + 2), @"   //    \\   ||____/   //      \\ ||     ||     ||".ToCharArray(),menuColor3),
            new MenuItem(new Position(menuX3, menuY3 + 3), @"  //======\\  ||    \\ (||      ||)||     ||     ||".ToCharArray(),menuColor3),
            new MenuItem(new Position(menuX3, menuY3 + 4), @" //        \\ ||     || \\      // \|     |/     ||".ToCharArray(),menuColor3),
            new MenuItem(new Position(menuX3, menuY3 + 5), @"//          \\||=====/   \\____//   \_____/      ||".ToCharArray(),menuColor3),
             };
        public static List<IRenderable> menu4 = new List<IRenderable>()
        {
            new MenuItem(new Position(menuX4, menuY4),     @"".ToCharArray(),menuColor4 ),
            new MenuItem(new Position(menuX4, menuY4 + 1), @" _______    _    _   __   ________".ToCharArray(),menuColor4 ),
            new MenuItem(new Position(menuX4, menuY4 + 2), @" ||         \\  //   ||      ||".ToCharArray(),menuColor4 ),
            new MenuItem(new Position(menuX4, menuY4 + 3), @" ||_____     \\//    ||      ||".ToCharArray(),menuColor4 ),
            new MenuItem(new Position(menuX4, menuY4 + 4), @" ||          //\\    ||      ||".ToCharArray(),menuColor4 ),
            new MenuItem(new Position(menuX4, menuY4 + 5), @" ||_____    //  \\   ||      ||".ToCharArray(),menuColor4 )
        };

        public static List<IRenderable> controlInfo = new List<IRenderable>()
        {
            new MenuItem(new Position(controlX1, controlY1), @"MOVING LEFT".ToCharArray(),controlColer1 ),
            new MenuItem(new Position(controlX1, controlY1+2), @"MOVING RIGHT".ToCharArray(), controlColer1),
            new MenuItem(new Position(controlX1, controlY1+4), @"ACTIVATE ABILITY".ToCharArray(),controlColer1 ),
            new MenuItem(new Position(controlX1, controlY1+6), @"PAUSE THE GAME".ToCharArray(),controlColer1 ),
            new MenuItem(new Position(controlX1, controlY1+8), @"MENU".ToCharArray(),controlColer1 ),
            new MenuItem(new Position(controlX1, controlY1+10), @"UP".ToCharArray(),controlColer1 ),      
            new MenuItem(new Position(controlX1, controlY1+12), @"DOWN".ToCharArray(),controlColer1 ),
            new MenuItem(new Position(controlX1, controlY1+14), @"Select".ToCharArray(),controlColer1 ),

            new MenuItem(new Position(controlX2, controlY2), Key.DefMovingLeft.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+2), Key.DefMovingRight.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+4), Key.DefActivate.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+6), Key.DefPause.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+8), Key.DefMenu.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+10), Key.DefMenuUp.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+12), Key.DefMenuDown.ToString().ToCharArray(),controlColer2),
            new MenuItem(new Position(controlX2, controlY2+14), Key.DefMenuSelect.ToString().ToCharArray(),controlColer2),

            new MenuItem(new Position(controlX3, controlY3), Key.MovingLeft.ToString().ToCharArray(), controlColer3),
            new MenuItem(new Position(controlX3, controlY3+2), Key.MovingRight.ToString().ToCharArray(), controlColer3),
            new MenuItem(new Position(controlX3, controlY3+4), Key.Activate.ToString().ToCharArray(), controlColer3),
            new MenuItem(new Position(controlX3, controlY3+6), Key.Pause.ToString().ToCharArray(), controlColer3)
        };

        public static List<IRenderable> select = new List<IRenderable>()
        {
            new MenuItem(new Position(5 ,6), @"===>".ToCharArray(), selectColor)
        };
    }
}